//
//  Person.m
//  OcDay6homework
//
//  Created by dllo on 16/5/28.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "Person.h"

@implementation Person

-(instancetype)initWithName:(NSString *)name withAge:(NSInteger)age{
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
    }
    return self;
}

+(instancetype)personWithName:(NSString *)name withAge:(NSInteger)age{
    Person *person = [[Person alloc] initWithName:name withAge:age];
    return person;
}

-(NSComparisonResult)compareWithName:(Person *)otherPerson{
    return [self.name compare:otherPerson.name];
}

-(NSComparisonResult)compareWithAge:(Person *)otherPerson{
    if (self.age < otherPerson.age){
        //返回Ascending时,排序方法不会交换对象的位置.
        return NSOrderedAscending;
    } else if(self.age > otherPerson.age){
        //返回Desending时,排序方法会将两个对象交换位置.
        return NSOrderedDescending;
    } else {
        return NSOrderedSame;
    }

}
-(NSString *)description{
    return [NSString stringWithFormat:@"%@ %ld",_name,_age];
}
@end
